/**
 * PLM项目npm包统一配置入口
 * 使用全局配置入口替代本地配置
 */

// 定义默认降级对象
const defaultConfig = {
  // MobX相关
  mobx: {
    observable: (obj) => obj,
    action: (fn) => fn,
    computed: (fn) => fn,
    configure: () => {},
    autorun: (fn) => { fn(); return () => {}; }
  },
  mobxMiniprogram: {
    observable: (obj) => obj,
    action: (fn) => fn,
    computed: (fn) => fn
  },
  createStoreBindings: (context, options) => {
    console.warn('[PLM] 使用兼容版createStoreBindings');
    return {
      updateStoreBindings: () => {},
      destroyStoreBindings: () => {}
    };
  },
  storeBindingsBehavior: Behavior({}),
  
  // 日期处理
  dayjs: function(date) {
    const d = date ? new Date(date) : new Date();
    return {
      format: (fmt) => {
        return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
      }
    };
  }
};

// 尝试导入全局npm包配置
let GlobalNpmConfig;
try {
  GlobalNpmConfig = require('../config/path_resolver.js').getRootConfigPath('path_resolver.js').getRootConfigPath('npm_config.js');
  console.info('[PLM] 成功加载全局npm配置');
} catch (e) {
  console.error('[PLM] 加载全局npm配置失败，使用本地兼容实现:', e.message);
  // 尝试直接加载各个库
  GlobalNpmConfig = defaultConfig;
}

// 导出配置
module.exports = GlobalNpmConfig; 